package cn.source.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import cn.source.mapper.ArtInforMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.domain.ArtInfor;
import cn.source.service.ArtInforService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 文章Controller
 *
 * @author zzroot
 * @date 2024-11-04
 */
@RestController
@RequestMapping("system/artApi")
public class ArtInforController extends BaseController
{
    @Autowired
    private ArtInforService artInforService;

    @Autowired
    private ArtInforMapper artInforMapper;

    /**
     * 查询文章列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ArtInfor artInfor)
    {
        startPage();
        List<ArtInfor> list = artInforService.selectArtInforList(artInfor);
        return getDataTable(list);
    }

    /**
     * 获取文章详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        ArtInfor artInfor =  artInforMapper.selectArtInforContentById(id);
        return AjaxResult.success(artInfor);
    }

    /**
     * 新增文章
     */
    @PreAuthorize("@ss.hasPermi('system:infor:add')")
    @Log(title = "文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArtInfor artInfor)
    {
        return toAjax(artInforService.insertArtInfor(artInfor));
    }

    /**
     * 修改文章
     */
    @PreAuthorize("@ss.hasPermi('system:infor:edit')")
    @Log(title = "文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArtInfor artInfor)
    {
        return toAjax(artInforService.updateArtInfor(artInfor));
    }

    /**
     * 删除文章
     */
    @PreAuthorize("@ss.hasPermi('system:infor:remove')")
    @Log(title = "文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(artInforService.deleteArtInforByIds(ids));
    }

    /**
     * 导出文章列表
     */
    @PreAuthorize("@ss.hasPermi('system:infor:export')")
    @Log(title = "文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArtInfor artInfor)
    {
        List<ArtInfor> list = artInforService.selectArtInforList(artInfor);
        ExcelUtil<ArtInfor> util = new ExcelUtil<ArtInfor>(ArtInfor.class);
        util.exportExcel(response, list, "文章数据");
    }
}
